/*
 * Created on 2005-5-16
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.haoxi.gateway.runner;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 针对连接，建立响应的接收和下发线程
 * 
 * @author star Preferences - Java - Code Style - Code Templates
 */

public abstract class AbsConnectorDaemon extends Thread {
    /**
     * Logger for this class
     */
    private static final Log log = LogFactory.getLog(AbsConnectorDaemon.class);

    private IRun[] queueThreads;

    /**
     * TODO
     */
    private int maxCanSubMTConnCount = 3;

    /**
     * TODO
     */
    private int maxCannotSubMTConnCount = 3;

    private int currentSubMTConnCount;
    private int currentReciveConnCount;
    private int currentNotSubMTCount;

    protected String name;

    abstract public IRun[] getThreads();

    public void run() {

        log.debug(name + "接收 Deamon init !!!");

        // init threads
        queueThreads = getThreads();
        if (queueThreads == null || queueThreads.length <= 0) {
            return;
        }

        int nSize = queueThreads.length;
        int i = 0;
        for (; i < nSize; i++) {
            if (null != queueThreads[i]) {
                new Thread(queueThreads[i]).start();
                log.debug("-------------------IRun:" + queueThreads[i].getName()
                        + " start !!!-------------");
            }
        }

        log.debug(name + " Deamon start:" + i + " threads !!!");
    }

    /**
     * @return Returns the currentSubMTConnCount.
     */
    public int getCurrentSubMTConnCount() {
        return currentSubMTConnCount;
    }

    /**
     * @param currentSubMTConnCount The currentSubMTConnCount to set.
     */
    public void setCurrentSubMTConnCount(int currentSubMTConnCount) {
        this.currentSubMTConnCount = currentSubMTConnCount;
    }

    /**
     * @return Returns the currentReciveConnCount.
     */
    public int getCurrentReciveConnCount() {
        return currentReciveConnCount;
    }

    /**
     * @param currentReciveConnCount The currentReciveConnCount to set.
     */
    public void setCurrentReciveConnCount(int currentReciveConnCount) {
        this.currentReciveConnCount = currentReciveConnCount;
    }

    /**
     * @return Returns the currentNotSubMTCount.
     */
    public int getCurrentNotSubMTCount() {
        return currentNotSubMTCount;
    }

    /**
     * @param currentNotSubMTCount The currentNotSubMTCount to set.
     */
    public void setCurrentNotSubMTCount(int currentNotSubMTCount) {
        this.currentNotSubMTCount = currentNotSubMTCount;
    }

    /**
     * @return Returns the maxCannotSubMTConnCount.
     */
    public int getMaxCannotSubMTConnCount() {
        return maxCannotSubMTConnCount;
    }

    /**
     * @param maxCannotSubMTConnCount The maxCannotSubMTConnCount to set.
     */
    public void setMaxCannotSubMTConnCount(int maxCannotSubMTConnCount) {
        this.maxCannotSubMTConnCount = maxCannotSubMTConnCount;
    }

    /**
     * @return Returns the maxCanSubMTConnCount.
     */
    public int getMaxCanSubMTConnCount() {
        return maxCanSubMTConnCount;
    }

    /**
     * @param maxCanSubMTConnCount The maxCanSubMTConnCount to set.
     */
    public void setMaxCanSubMTConnCount(int maxCanSubMTConnCount) {
        this.maxCanSubMTConnCount = maxCanSubMTConnCount;
    }

}
